home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 3 / ct-rom iiib.zip / ct-rom iiib / WINDOWS / UTILITY / DESKTOP / W_ONE49 / SPLIT.CP_ / SPLIT.CP
Text File  |  1994-04-27  |  3KB  |  90 lines

  1. #include "split.h"
  2.  
  3. /******************************************************************\
  4. *                                                                  *
  5. *           w       w                oooo                           *
  6. *           w       w  iii  n   n   o    o   n   n  eeee            *
  7. *           w       w   i   nn  n  o      o  nn  n  e               *
  8. *           w   w   w   i   n n n  o      o  n n n  eee             *
  9. *              w w w w    i   n  nn   o    o   n  nn  e               *
  10. *              w   w    iii  n   n    oooo    n   n  eeee            *
  11. *                                                                      *
  12. *     C o m m a n d   L a n g u a g e   I n t e r p r e t e r      *
  13. *                                                                      *
  14. *                                                                      *
  15. *    Written by Lucien Cinc                                         *
  16. *    Copyright (c) 1992, 1993                                       *
  17. *                                                                  *
  18. \******************************************************************/
  19.  
  20. int split(char *path, long offset);
  21.  
  22. int main(void)
  23. {
  24.     int offset;
  25.     char *sp;
  26.  
  27.     sp = args();                // parse command line switches
  28.     while(*sp)
  29.         switch(*sp++) {
  30.             case 'v' :          // show version information
  31.                        printf("%cVersion %c%d.%01d\n", WHITE, YELLOW, VERSION / 10, VERSION % 10);
  32.                        return 0;
  33.             default:            // invalid switch
  34.                        perror("Invalid switch");
  35.                        return 1;
  36.         }
  37.  
  38.     if (argnstr()) {            // no string arguments
  39.         perror("Invalid argument");
  40.         return 1;
  41.     }
  42.  
  43.     if (argc() != 2) {
  44.         perror("To many or few arguments");
  45.         return 1;
  46.     }
  47.  
  48.     return split(argabs(1), atol(argv(2)));    // split the file
  49. }
  50.  
  51. int split(char *path, long offset)
  52. {
  53.     long num;
  54.     char dst[MAXPATH], src[MAXPATH];
  55.  
  56.     strcpy(dst, path);
  57.     strcpy(src, path);
  58.  
  59.     if ((num = filesize(src)) == -1) {
  60.         perror("Invalid path or file name");
  61.         return 1;
  62.     }
  63.  
  64.     limit(num);    // status bar limit
  65.  
  66.     if (offset < 0 || offset > num) {
  67.         perror("Out of range");
  68.         empty();
  69.         return 1;
  70.     }
  71.  
  72.     strcpy(strrchr(dst, '.'), ".1");        // first half
  73.     printf("%c%s %c%9ld%c\n", GREEN, unixpath(padfilename(dst)), YELLOW, offset, LIGHTGRAY);
  74.     if (filencpy(dst, src, offset, 0, O_CREATNEW, INC_BYTE) == -1) {
  75.         empty();
  76.         return 1;
  77.     }
  78.  
  79.     strcpy(strrchr(dst, '.'), ".2");        // second half
  80.     printf("%c%s %c%9ld%c\n", GREEN, unixpath(padfilename(dst)), YELLOW, num - offset, LIGHTGRAY);
  81.     if (filencpy(dst, src, -1, offset, O_CREATNEW, INC_BYTE) == -1) {
  82.         empty();
  83.         return 1;
  84.     }
  85.  
  86.     empty();        // finished with status bar
  87.  
  88.     return 0;
  89. }
  90.